package com.jmi.chmtrace.back.Service.Imp;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jmi.chmtrace.back.Mapper.UserMapper;
import com.jmi.chmtrace.back.Pojo.User;
import com.jmi.chmtrace.back.Service.UserService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public List<User> selectAllUSer() {
        return userMapper.selectList(null);
    }

    @Override
    public boolean UserLogin(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("userName",user.getUserName());
        User loginUser = userMapper.selectOne(wrapper);
        if (ObjectUtils.isEmpty(loginUser)) {
            return false;
        } else return StringUtils.equals(loginUser.getPassword(), user.getPassword())&&StringUtils.equals(loginUser.getChainUsername(), user.getChainUsername());
    }
}
